package yunjiao.javatutorials.guava.concurrent.interrupt;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;

/**
 * 生产环境配置
 *
 * @author yangyunjiao
 */
@Slf4j
public class ProductionInterruptAwareCondition extends InterruptAwareCondition {
    public ProductionInterruptAwareCondition(Condition delegate) {
        super(delegate);
    }

    @Override
    public void await() throws InterruptedException {
        try {
            super.await();
        } catch (InterruptedException e) {
            log.warn("Condition await interrupted", e);
            throw e;
        }
    }

    @Override
    public boolean await(long time, TimeUnit unit) throws InterruptedException {
        try {
            return super.await(time, unit);
        } catch (InterruptedException e) {
            log.warn("Timed condition await interrupted after {} {}", time, unit, e);
            throw e;
        }
    }
}
